package homework.mission2;

public class FindSubString {
    public static void main(String[] args) {
        String bigStr = "asdafghjka";
        String smallStr = "aaasdfg";

        System.out.println(findSubStr(bigStr, smallStr));
    }

    /**
     * 依次递减的截取小字符串来与大串做比较
     * @param bigStr
     * @param smallStr
     * @return
     */
    private static String findSubStr(String bigStr, String smallStr) {
        for (int i = 0; i < smallStr.length(); i++) {
            for (int j = 0, k = smallStr.length() - i; k != smallStr.length() + 1 ; j++, k ++) {
                String tmp = smallStr.substring(j, k);

                if (bigStr.contains(tmp)) {
                    return tmp;
                }
            }
        }

        return null;
    }
}
